

(defun read-one-pair (strm)
  (read-from-string (concatenate 'string "(" (read-line strm nil "0 0") ")")))

(defun read-values-from-file (file-name)
  (with-open-file (valin file-name :direction :input)
    (loop for pair = (read-one-pair valin)
          until (equal '(0 0) pair)
          collect pair)))

(defun trapezoid-area (pa pb)
  (let ((xa (first pa)) (ya (second pa))
        (xb (first pb)) (yb (second pb)))
    (* (- xb xa) (/ (+ ya yb) 2.0))))

(defun calculate-area-under-function (pairs)
  (if (< (list-length pairs) 2)
      0
      (+ (trapezoid-area (first pairs) (second pairs))
         (calculate-area-under-function (cdr pairs)))))

(print
 (calculate-area-under-function
  (read-values-from-file "D:/Projects/code-storage-my/test1.txt")))


